# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=ocaml-conduit
pkgver=6.1.0
pkgrel=0
_pkgreal=conduit
pkgdesc="Network connection establishment library"
url="https://github.com/mirage/ocaml-conduit"
arch="all !riscv64 !loongarch64" # ocaml
license="ISC"
depends_dev="
	$pkgname=$pkgver-r$pkgrel
	ocaml-astring-dev
	ocaml-ca-certs-dev
	ocaml-ipaddr-dev
	ocaml-logs-dev
	ocaml-lwt-dev
	ocaml-lwt_ssl-dev
	ocaml-ppx_sexp_conv-dev
	ocaml-sexplib-dev
	ocaml-tls-dev
	ocaml-uri-dev
	"
makedepends="
	$depends_dev
	dune
	ocaml
	"
checkdepends="ocaml-lwt_log-dev"
subpackages="$pkgname-dev"
source="$_pkgreal-$pkgver.tar.bz2::https://github.com/mirage/ocaml-conduit/releases/download/v$pkgver/conduit-$pkgver.tbz"
builddir="$srcdir/$_pkgreal-$pkgver"

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	dune build --verbose \
		-p conduit,conduit-lwt,conduit-lwt-unix
}

check() {
	dune runtest --build-dir=.testenv --verbose \
		-p conduit,conduit-lwt,conduit-lwt-unix
}

package() {
	dune install --destdir="$pkgdir" --docdir=/.omit \
		conduit conduit-lwt conduit-lwt-unix
}

dev() {
	default_dev

	cd "$pkgdir"

	local path; find usr/lib/ocaml \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\) | while read -r path
	do
		amove "$path"
	done
}

prepare_py_provides() {
	local datadir="${subpkgdir:-$pkgdir}"
	local pkgbasedir=${pkgbasedir:-"$startdir/pkg"}
	local controldir="$pkgbasedir"/.control.${subpkgname:-$pkgname}

	options_has "!tracedeps" && return 0

	ocaml4-abuild-find provides \
		"$datadir"/usr/lib/ocaml \
		"$controldir" \
		"$pkgver-r$pkgrel"
}

scan_python3_dependency() {
	local controldir="$2" datadir="$3"

	ocaml4-abuild-find requires \
		"$datadir"/usr/lib/ocaml \
		"$controldir"
}

sha512sums="
308041a9cccf5b01827365ae9e75915bf33c812658ff1a802b275827f4c9af98dd991df9106a5b8d70374cc0d41398621bbafd8de829acfef4cb86e6b9523712  conduit-6.1.0.tar.bz2
"
